<template>
<div>
  <div v-if="!showEdit && !showDetail" class="app-container">
    <!-- 三个下拉框 -->
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label=一级分类>
        <el-select v-model="formInline.region" placeholder="活动区域">
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label=二级分类>
        <el-select v-model="formInline.region" placeholder="活动区域">
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label=资讯来源>
        <el-select v-model="formInline.region" placeholder="活动区域">
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="资讯标题" >
        <el-input  v-model="formInline.user" placeholder="请输入标题关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading" border fit highlight-current-row>
      <!-- <el-table-column align="center" label='ID' width="95">
        <template slot-scope="scope">
          {{scope.$index}}
        </template>
      </el-table-column> -->
      <el-table-column label="分类级别" width="120">
        <template slot-scope="scope">
          <span>{{scope.row.author}}</span>
        </template>
      </el-table-column>
      <el-table-column label="分类名称" width="147" align="center">
         <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{scope.row.status}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="资讯来源" width="140" align="center">
        <template slot-scope="scope">
          {{scope.row.pageviews}}
        </template>
      </el-table-column>
      <el-table-column class-name="status-col"  label="资讯标题" width="450" align="center">
        <template slot-scope="scope" >
          <span @click='onLookDetail' class="title">{{scope.row.title}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="当前状态" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span>{{scope.row.display_time}}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        fixed="right"
        label="操作"
        width="150">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
          <el-button @click="handleEdit(scope.row)" type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
  <!-- 编辑 -->
  <Edit v-show="showEdit"></Edit>
  <!-- 查看 -->
  <Detail v-show="showDetail"></Detail>
</div>
</template>

<script>
import { getList } from '@/api/table'
import Detail from './components/detail'
import Edit from './components/edit'
export default {
  components: { Detail, Edit },
  data() {
    return {
      showEdit: false,
      showDetail: false,
      list: null,
      listLoading: true,
      formInline: {
        user: '',
        region: ''
      }
    }
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  created() {
    this.fetchData()
  },
  mounted() {
    this.loadcat1()
  },
  methods: {
    loadcat1() {
      this.axios.get('/api/').then(() => {})
    },
    onLookDetail() {
      this.showDetail = true
    },
    handleClick(row) {
      console.log(row)
    },
    handleEdit(row) {
      console.log(row)
      this.showEdit = true
    },
    onSubmit() {
      console.log('submit!')
    },
    fetchData() {
      this.listLoading = true
      // this.listLoading = false
      getList(this.listQuery).then(response => {
        this.list = response.data.items
        this.listLoading = false
      })
    }
  }
}
</script>
<style>
.title{
  color: #549ff8;
  text-decoration: underline;
  cursor: pointer;
}
</style>



